package com.visceb.backstage.controller;
import com.visceb.backstage.dao.loginRepository;
import com.visceb.backstage.entity.login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("login")
@CrossOrigin()
public class loginController {
    @Autowired
    private loginRepository loginrepository;

    @RequestMapping(value ="/loginByUser", method = RequestMethod.GET)
    @ResponseBody
    public List<login> findUser(String user) {
        return loginrepository.findAllByUser(user);
    }

//    登录错误监测，后期可以进三日
    @RequestMapping(value ="/loginError", method = RequestMethod.GET)
    @ResponseBody
    public List<login> loginError(String state, String day) {
        return loginrepository.findAllByStateAndDATA(state, day);
//        return loginrepository.findAllByState(state);
    }

//    删除
    @RequestMapping(value ="/loginDelte", method = RequestMethod.POST)
    @ResponseBody
    public String loginDel(int id) {

        System.out.println("the userId is "+id);

        if(loginrepository.deleteById(id)>0){
            return "数据删除成功!";
        }
        return "删除失败";
    }


    @RequestMapping(value="/deleteBook", method = RequestMethod.POST)
    @ResponseBody
    public int deleteBookByName(int id) {
        System.out.println(id);
        System.out.println(loginrepository.findAllById(id));
        int book = loginrepository.deleteAllById(id);
        return book;
    }
}